package control;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Categories;
public class EditCat extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public EditCat() {super();}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String cid = request.getParameter("cid");
		String n = request.getParameter("n");
		String pt = request.getParameter("pt");
		String uid = request.getParameter("uid");
		Categories categories = new Categories(Integer.parseInt(cid), Integer.parseInt(uid), n, Integer.parseInt(pt));
		if (categories.checkNewName()!="") {
			request.setAttribute("n", n);
			request.setAttribute("pt", pt);
			request.setAttribute("en",categories.checkNewName());
			RequestDispatcher transferexist = getServletContext().getRequestDispatcher("/a/categories.jsp?site=e");
			transferexist.forward(request, response);
		} else {
			System.out.println(categories.upDate());
			System.out.println(categories.toString());
			request.setAttribute("m", "edit-cok");
			request.setAttribute("r","vc");
			RequestDispatcher transfer = getServletContext().getRequestDispatcher("/a/message.jsp");
			transfer.forward(request, response);
		}
	}
}
